package com.ihg.hiex.entity.session.during.report;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.ihg.hiex.entity.session.during.SessionCalibration;
import com.ihg.hiex.entity.session.during.SessionCalibrationComment;
import com.ihg.hiex.entity.session.during.SessionCalibrationCompetency;
import com.ihg.hiex.entity.session.during.SessionCalibrationRecommendation;
import com.ihg.hiex.entity.session.during.SessionCalibrationStatus;
import com.ihg.hiex.entity.user.Role;

/**
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "session_report_writing")
public class SessionReportWriting {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @Embedded
    private SessionReportCompetency sessionReportCompetency;
    
    @Embedded
    private SessionReportComment sessionReportComment;
    
    @Embedded
    private SessionReportRecommendation sessionReportRecommendation;
    
    /** 状态 */
    @Enumerated(EnumType.STRING)
    private SessionCalibrationStatus status;
    
    /** 修改角色 */
    @Enumerated(EnumType.STRING)
    private Role role;
    
    /** 修改人 */
    private Long operator;
    
    /** 最后修改时间 */
    private Date lastUpdateTime;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private SessionCalibration sessionCalibration;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * 
     */
    public SessionReportWriting() {
        
    }
    
    /**
     * 
     * @param sessionCalibration
     * @param competencies
     * @param comment
     * @param calibrationComment
     * @param recommendation
     * @param role
     * @param operator
     */
    public SessionReportWriting(SessionCalibration sessionCalibration, Map<String, SessionCalibrationCompetency> competencies,
                                SessionReportComment comment, SessionCalibrationComment calibrationComment,
                                SessionCalibrationRecommendation recommendation, List<String> chooseComments,
                                String chooseValue, Role role, Long operator) {
        this.sessionReportCompetency = new SessionReportCompetency(competencies);
        this.sessionReportComment = new SessionReportComment(calibrationComment, comment, chooseComments, chooseValue);
        this.sessionReportRecommendation = new SessionReportRecommendation(recommendation);
        this.status = SessionCalibrationStatus.CREATED;
        this.role = role;
        this.operator = operator;
        this.lastUpdateTime = new Date();
        this.sessionCalibration = sessionCalibration;
        this.disabled = false;
    }
    
    /**
     * 
     * @param sessionCalibration
     * @param competencies
     * @param comment
     * @param recommendation
     * @param calibrationRecommendation
     * @param role
     * @param operator
     */
    public SessionReportWriting(SessionCalibration sessionCalibration, Map<String, SessionCalibrationCompetency> competencies,
                                SessionCalibrationComment comment, SessionReportRecommendation recommendation,
                                SessionCalibrationRecommendation calibrationRecommendation,
                                Role role, Long operator) {
        this.sessionReportCompetency = new SessionReportCompetency(competencies);
        this.sessionReportComment = new SessionReportComment(comment);
        this.sessionReportRecommendation = new SessionReportRecommendation(calibrationRecommendation, recommendation);
        this.status = SessionCalibrationStatus.CREATED;
        this.role = role;
        this.operator = operator;
        this.lastUpdateTime = new Date();
        this.sessionCalibration = sessionCalibration;
        this.disabled = false;
    }
    
    /**
     * 
     * @param sessionCalibration
     * @param sessionReportCompetency
     * @param calibrationComment
     * @param recommendation
     * @param role
     * @param operator
     */
    public SessionReportWriting(SessionCalibration sessionCalibration, SessionReportCompetency sessionReportCompetency, SessionCalibrationComment calibrationComment, SessionCalibrationRecommendation recommendation,
        Role role, Long operator) {
      this.sessionReportCompetency = sessionReportCompetency;
      this.sessionReportComment = new SessionReportComment(calibrationComment);
      this.sessionReportRecommendation = new SessionReportRecommendation(recommendation);
      this.status = SessionCalibrationStatus.CREATED;
      this.role = role;
      this.operator = operator;
      this.lastUpdateTime = new Date();
      this.sessionCalibration = sessionCalibration;
      this.disabled = false;
      
    }
    
    /**
     * 
     * @param recommendation
     * @return
     */
    public SessionReportWriting editRecommendation(SessionReportRecommendation recommendation) {
        this.sessionReportRecommendation = this.sessionReportRecommendation.edit(recommendation);
        return this;
    }
    
    /**
     * 
     * @param comment
     * @param chooseComments
     * @return
     */
    public SessionReportWriting editComment(SessionReportComment comment, List<String> chooseComments) {
        this.sessionReportComment = this.sessionReportComment.edit(comment, chooseComments);
        return this;
    }
    
    /**
     * 
     * @param sessionReportCompetency
     * @return
     */
    public SessionReportWriting editComptency(SessionReportCompetency sessionReportCompetency) {
      this.sessionReportCompetency = this.sessionReportCompetency.editEffective(sessionReportCompetency);
      return this;
    }
    
    /**
     * 
     * @param status
     * @return
     */
    public SessionReportWriting changeStatus(SessionCalibrationStatus status) {
        this.status = status;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the sessionReportCompetency
     */
    public SessionReportCompetency getSessionReportCompetency() {
        return sessionReportCompetency;
    }

    /**
     * @return the sessionReportComment
     */
    public SessionReportComment getSessionReportComment() {
        return sessionReportComment;
    }

    /**
     * @return the sessionReportRecommendation
     */
    public SessionReportRecommendation getSessionReportRecommendation() {
        return sessionReportRecommendation;
    }

    /**
     * @return the status
     */
    public SessionCalibrationStatus getStatus() {
        return status;
    }

    /**
     * @return the role
     */
    public Role getRole() {
        return role;
    }

    /**
     * @return the operator
     */
    public Long getOperator() {
        return operator;
    }

    /**
     * @return the lastUpdateTime
     */
    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    /**
     * @return the sessionCalibration
     */
    public SessionCalibration getSessionCalibration() {
        return sessionCalibration;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param sessionReportCompetency the sessionReportCompetency to set
     */
    public void setSessionReportCompetency(SessionReportCompetency sessionReportCompetency) {
        this.sessionReportCompetency = sessionReportCompetency;
    }

    /**
     * @param sessionReportComment the sessionReportComment to set
     */
    public void setSessionReportComment(SessionReportComment sessionReportComment) {
        this.sessionReportComment = sessionReportComment;
    }

    /**
     * @param sessionReportRecommendation the sessionReportRecommendation to set
     */
    public void setSessionReportRecommendation(SessionReportRecommendation sessionReportRecommendation) {
        this.sessionReportRecommendation = sessionReportRecommendation;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(SessionCalibrationStatus status) {
        this.status = status;
    }

    /**
     * @param role the role to set
     */
    public void setRole(Role role) {
        this.role = role;
    }

    /**
     * @param operator the operator to set
     */
    public void setOperator(Long operator) {
        this.operator = operator;
    }

    /**
     * @param lastUpdateTime the lastUpdateTime to set
     */
    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    /**
     * @param sessionCalibration the sessionCalibration to set
     */
    public void setSessionCalibration(SessionCalibration sessionCalibration) {
        this.sessionCalibration = sessionCalibration;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
